﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FrbaCommerce.Calificar_Vendedor
{
    public partial class FormCalificar : Form
    {

        
        private int user_id, vendedor_id, cod_pub, cod_compra;
        Calificar_Vendedor.ListadoCompras formPadre;

        public FormCalificar(int user_id, DataGridViewRow fila, Calificar_Vendedor.ListadoCompras formPadre)
        {
            InitializeComponent();
            this.user_id = user_id;
            this.formPadre = formPadre;

            cod_pub = Convert.ToInt32(fila.Cells["Publicación"].Value.ToString());
            cod_compra = Convert.ToInt32(fila.Cells["Código"].Value.ToString());

            SqlConnection con = Program.obtenerConexion();

            SqlCommand obtenerVendedor = new SqlCommand("SELECT pub_usuario_id FROM [Monkey_Coders].Publicaciones"
                + " WHERE pub_cod = " + cod_pub, con);
            vendedor_id = Convert.ToInt32(obtenerVendedor.ExecuteScalar());

            comboBoxEstrellas.SelectedIndex = 0;
            comboBoxDetalle.SelectedIndex = 0;

        }

        private void textBoxDesc_TextChanged(object sender, EventArgs e)
        {

        }

        private void comboBoxDetalle_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void radioButtonPerso_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButtonPerso.Checked)
            {
                comboBoxDetalle.Enabled = false;
                textBoxDesc.Enabled = true;
            }
            else
            {
                comboBoxDetalle.Enabled = true;
                textBoxDesc.Enabled = false;
            }

        }


        private void comboBoxEstrellas_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void FormCalificar_Load(object sender, EventArgs e)
        {

        }

        private void buttonCalificar_Click(object sender, EventArgs e)
        {
            SqlConnection con = Program.obtenerConexion();

            SqlCommand calificar = new SqlCommand("INSERT INTO Monkey_Coders.Calificaciones "
                + "(cal_usuario_id, cal_vendedor_id, cal_compra_id, cal_cant_estrellas, cal_descripcion, cal_fecha_calificacion)"
                + " VALUES (@cal_usuario,@cal_vendedor,@cal_compra, @estrellas,@desc, @fecha)", con);
            calificar.Parameters.Add("cal_usuario", SqlDbType.Int, 18).Value = user_id;
            calificar.Parameters.Add("cal_vendedor", SqlDbType.Int, 18).Value = vendedor_id;
            calificar.Parameters.Add("cal_compra", SqlDbType.Int, 18).Value = cod_compra;
            calificar.Parameters.Add("estrellas", SqlDbType.Int, 18).Value = Convert.ToInt32(comboBoxEstrellas.Text);
            calificar.Parameters.Add("desc", SqlDbType.VarChar, 255).Value = textBoxDesc.Text;
            calificar.Parameters.Add("fecha", SqlDbType.DateTime,50).Value = Program.FechaActual;
            calificar.ExecuteNonQuery();

            MessageBox.Show("Usuario Calificado!");
            formPadre.buscar();
            this.Close();

        }

    }
}
